import { Global, Module } from '@nestjs/common';
import { RedisService } from './redis.service';
import { createClient } from 'redis'
import { ConfigService } from '@nestjs/config';
@Global()
@Module({
    providers: [
        RedisService,
        {
            provide: 'REDIS_CLIENT',
            useFactory: async (configService: ConfigService) => {
                const client = createClient({
                    socket: configService.get("redis.socket"),
                    database: configService.get("redis.db")
                });
                await client.connect();
                return client;
            },
            inject: [ConfigService],
        }
    ],
    exports: [RedisService],
})
export class RedisModule { }
